package com.mes.schedule.dao;

import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.stereotype.Repository;

import com.mes.common.dao.BasicDao;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.mes.schedule.dao.iface.IScheduleEquipmentDao;
import com.mes.schedule.domain.ScheduleEquipment;

@Repository
public class ScheduleEquipmentDao extends BasicDao<ScheduleEquipment> implements IScheduleEquipmentDao{
	private static final Log log = LogFactory.getLog(ScheduleEquipmentDao.class);
	
	/**
	 * @see 这个方法用于ScheduleEquipmentDataAccess
	 * @param scheduleUid
	 * @param resUid
	 * @return
	 */
	public List<ScheduleEquipment> findAllBy(String scheduleUid, String resUid) {
		  
		// TODO Auto-generated method stub
		List<ScheduleEquipment> list = new ArrayList<ScheduleEquipment>();
		try {
			Session session = this.getSession();
			Criteria crit = session.createCriteria(ScheduleEquipment.class);
			//crit.add(Restrictions.eq("creatorId", creatorId));
			crit.add(Restrictions.eq("scheduleUid", scheduleUid));
			crit.add(Restrictions.eq("resUid", resUid));
			list = crit.list();
			
		} catch (DataAccessResourceFailureException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	
}
